/***********************************************************************
 * Module:  Epreuve.java
 * Author:  Alexandro
 * Purpose: Defines the Class Epreuve
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;

public class Epreuve implements InterfaceDAO {
   private int session = 1;
   private int codeEpr;
   private int coefficient;
   private boolean effectue;
   
   public EpreuveRendu[] notes;
   
   public Matiere matiereA;
   public TypeEpreuve typeEpreuveB;
   
   public int getSession() {
      return session;
   }
   
   /** @param newSession */
   public void setSession(int newSession) {
      session = newSession;
   }
   
   public int getCodeEpr() {
      return codeEpr;
   }
   
   /** @param newCodeEpr */
   public void setCodeEpr(int newCodeEpr) {
      codeEpr = newCodeEpr;
   }
   
   public int getCoefficient() {
      return coefficient;
   }
   
   /** @param newCoefficient */
   public void setCoefficient(int newCoefficient) {
      coefficient = newCoefficient;
   }
   
   public boolean getEffectue() {
      return effectue;
   }
   
   /** @param newEffectue */
   public void setEffectue(boolean newEffectue) {
      effectue = newEffectue;
   }
   
   public int insert(int[] param) {
      
      
       
        try {			
			dao.DAODataConnection.executer("INSERT INTO epreuve(session,code_epr,coefficient,effectue)"+
										   "VALUES("+getSession()+","+getCodeEpr()+","+getCoefficient()+","+getEffectue()+ ");");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public Object[] select(int[] param) {
      
       try {			
			
			ResultSet table = dao.DAODataConnection.executerQuery("SELECT * FROM epreuve");											
			Vector sortie = new Vector();			
			while(table.next() )	
			{
				Epreuve neuf = new Epreuve();
				neuf.setSession(table.getInt(1));
				neuf.setCodeEpr(table.getInt(2));				
				neuf.setCoefficient(table.getInt(6));				
				neuf.setEffectue(table.getBoolean(7));				
				
				sortie.add(neuf);				
			}		
			return sortie.toArray();			
			}
			
		catch(Exception e){ System.out.println(e); }		
		
		return null;
		
		
		
   }
   
   public int delete(int[] param) {
      
      
      
      try {			
			dao.DAODataConnection.executer("DELETE FROM epreuve WHERE session="+getSession()+" and code_epr="+getCodeEpr());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public int update(int[] params) {
      
      
       try {			
			dao.DAODataConnection.executer("UPDATE epreuve SET "+										   
										   "cod_mat="+params[0]+","+
										   "code_mod="+params[1]+","+
										   "type="+params[2]+","+
										   "coefficient="+getCoefficient()+ ","+
										   "effectue="+getEffectue()+ 
										   " where session="+getSession()+" and code_epr="+getCodeEpr());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }

}